<html>
    <head>
        <title>DoReMon web 2</title>
        <link href="public/css/css.css" rel="stylesheet" type="text/css">
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

    </head>
    <body>
        <?php
        require_once './model/works.php';
        $keyword = new Works();
        $keyword->table_name = "works";
        ?>
        <?php
        if (!isset($_GET["page"]))
            $page = 1;
        else
            $page = $_GET["page"];
        $total = $keyword->countWords();
        ?>
        <div class="tong">
            <div class="menu">
                <ul>
                    <li><a href="index.php"> TRANG CHỦ</a></li>
                    <li><a href="#">GIỚI THIỆU</a></li>
                    <li><a href="#">SẢN PHẨM</a>
                        <ul>
                            <li><a href="#">APPLE</a></li>
                            <li><a href="#">DELL</a></li>
                            <li><a href="#">SAMSUNG</a></li>
                            <li><a href="#">PANASONIC</a></li>
                        </ul>
                    </li>   

                    <li><a href="#">THIẾT BỊ MẠNG</a>
                        <ul>
                            <li><a href="#">USB 3G</a></li>
                            <li><a href="#">HUB-SWICHT</a></li>
                            <li><a href="#">CABLE MẠNG</a></li>
                            <li><a href="#">KHÁC</a></li>
                        </ul>
                    </li>
                    <li><a href="#"> THIẾT BỊ VĂN PHÒNG</a>
                        <ul>
                            <li><a href="#">MÁY IN</a></li>
                            <li><a href="#">MÁY SCAN</a></li>
                            <li><a href="#">MÁY FAX</a></li>
                            <li><a href="#">MÁY TÍNH TIỀN</a></li>
                        </ul>
                    </li>
                    <li><a href="#">LIÊN HỆ</a></li>
                </ul>

            </div>

            <img src="public/image/a.jpg"/>



            <div id="boder"></div>
            <header>
                <div id="phai">
                    <p>User name</p>
                    <input type="text" name="user_name">
                    <p>Password <strong>(*)</strong></p>
                    <input type="password" name="password"></br>
                    <p id="input_st"><a href="#">Log in</a></p>
                </div>
                <section>

                    <div class="navNext"> 
                        <nav>
                            <ul>
                                <li><a href="index.php?page=1">Fist</a></li>
                                <li><a href="index.php?page=<?php echo $_GET['page'] = 1 ?>">Pre</a></li>
                                <?php $max_page = 7; ?>
                                <?php for ($i = 1; $i <= $max_page; $i++): ?>
                                    <?php if (($_GET["page"] == 1) || ($_GET["page"] == 2) || ($_GET["page"] == 3) || ($_GET["page"] == 4)): ?>            
                                        <?php for ($i = 1; $i <= $max_page; $i++): ?>
                                            <li> <a href='index.php?page=<?php echo $i; ?> '><?php echo $i ?></a></li>
                                            <?php if ($_GET["page"] == $i): ?>
                                                <?php $keyword->begin; ?>
                                                <?php $keyword->end = PAGE; ?>
                                            <?php endif; ?>
                                        <?php endfor; ?>
                                    <?php elseif (($_GET["page"] == $total / PAGE) || ($_GET["page"] == $total / PAGE - 1) || ($_GET["page"] == $total / PAGE - 2) || ($_GET["page"] == $total / PAGE - 3)): ?>        
                                        <?php for ($i = $total / PAGE - $max_page; $i <= $total / PAGE; $i++): ?>
                                            <li><a href='index.php?page=<?php echo $i; ?> '><?php echo $i ?></a></li>
                                            <?php if ($_GET["page"] == $i): ?>
                                                <?php $keyword->begin; ?>
                                                <?php $keyword->end = PAGE; ?>
                                            <?php endif; ?>
                                        <?php endfor; ?>
                                    <?php else : ?>
                                        <?php for ($i = $_GET["page"] - 3; $i <= $_GET["page"] + 3; $i++): ?>
                                            <li> <a href='index.php?page=<?php echo $i; ?> '><?php echo $i ?></a></li>
                                            <?php if ($_GET["page"] == $i): ?>
                                                <?php $keyword->begin; ?>
                                                <?php $keyword->end = PAGE; ?>
                                            <?php endif; ?>
                                        <?php endfor; ?>
                                    <?php endif; ?> 
                                <?php endfor; ?>                   
                                <li> <a href="index.php?page=<?php echo $_GET['page'] + 1 ?>">Next</a></li>
                                <li><a href="index.php?page=<?php echo $total / PAGE ?>">Last</a></li>
                                <?php $keywords = $keyword->select($page); ?>
                            </ul>
                        </nav>

                    </div>

                    <div id="khoangcach">
                        <table border="1px">
                            <tr class="a"> 
                                <td>ID</td>
                                <td>name</td>
                                <td>location</td>
                                <td>company_address</td>
                                <td>images</td>
                                <td>Operation</td>
                            </tr>
                            <?php foreach ($keywords as $go): ?>
                                <tr class="b">
                                    <td><?php echo $go['id']; ?></td>
                                    <td><?php echo $go['name']; ?></td>
                                    <td><?php echo $go['location']; ?></td>
                                    <td><?php echo substr($go['company_address'], 0, 100); ?></td>
                                    <td><img src="<?php echo$go['image'] ?>" with="100px" height="100px"></td>
                                    <td class="dk">
                                        <img src="public/image/notes_edit-1394601700.png" width="15px" height="15px">   <a href="index_edit.php?id=<?php echo $go['id']; ?>">Edit</a>
                                        <img src="public/image/view.png" width="15px" height="15px"><a href="upload_file.php">View</a>
                                        <img src="public/image/folder_delete-1394601697.png" width="15px" height="15px"><a href="upload_file.php">Deleted</a>
                                    </td>
                                </tr>
                            <?php endforeach; ?>
                        </table>
                    </div>
                </section>


            </header>

        </div>

    </body>
</html>
